import {defineStore} from "pinia";
import {login} from '@/api/Login/login'
export const useTokenStore = defineStore('login', {
    state:()=>({
        user:{
            token:'',
            username:'',
        }
    }),
    actions:{
       async setToken({tel,password,verify}:any,success:Function,fail:Function){
         const res= await login({
               tel: tel.value,
               password: password.value,
               verify
           })
           if(res.status===200){
               this.user.token=res.data.token
               this.user.username=res.data.username
               success()
           }else {
               fail()
           }
        },
        clearToken():any{
            this.user.token=''
            this.user.username=''
        }
    },
    persist:{
        enabled:true,
        strategies:[{
            key:'user',
            storage:localStorage
        }]
    }
}as any)